<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.5"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>SWM34S_LVGL7.11_SWMUI: C:/Users/DELL/Desktop/Commit/lvgl/SWM34S_LVGL7.11_SWMUI_20230515/APP/Common Module/FlashDisk.c 源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">SWM34S_LVGL7.11_SWMUI<span id="projectnumber">&#160;V7.9</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.9.5 -->
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_0ca16891106f5a3e9ad635a0d6c5f98f.html">APP</a></li><li class="navelem"><a class="el" href="dir_df4e0e4e72f77ab290fd1a24f190250a.html">Common Module</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle"><div class="title">FlashDisk.c</div></div>
</div><!--header-->
<div class="contents">
<a href="_flash_disk_8c.html">浏览该文件的文档.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno">    1</span> </div>
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno">   22</span><span class="preprocessor">#include &lt;string.h&gt;</span></div>
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno">   23</span><span class="preprocessor">#include &quot;<a class="code" href="_flash_disk_8h.html">FlashDisk.h</a>&quot;</span></div>
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno">   24</span> </div>
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno">   25</span><span class="comment">/*******************************************************************************************************************************************</span></div>
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno">   26</span><span class="comment"> * Private Define</span></div>
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno">   27</span><span class="comment"> *******************************************************************************************************************************************/</span></div>
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"><a class="line" href="_flash_disk_8c.html#a129a46ca48c8d54a2652680000bfdffc">   28</a></span><span class="preprocessor">#define IO_SPI_ENABLE </span></div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno">   30</span><span class="comment">/*******************************************************************************************************************************************</span></div>
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno">   31</span><span class="comment"> * Private Variable</span></div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno">   32</span><span class="comment"> *******************************************************************************************************************************************/</span></div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno"><a class="line" href="_flash_disk_8c.html#a3a9f0f889d7fd26864b496dd569df89a">   34</a></span><span class="keyword">static</span> <span class="keyword">volatile</span> uint32_t <a class="code hl_variable" href="_flash_disk_8c.html#a3a9f0f889d7fd26864b496dd569df89a">Flash_Block_Addr</a> = 0xFFFFFFFF;</div>
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"><a class="line" href="_flash_disk_8c.html#ac59b50f1dca0139b7a79fa6a258f3bbb">   36</a></span><span class="keyword">static</span> <span class="keyword">volatile</span> uint32_t <a class="code hl_variable" href="_flash_disk_8c.html#ac59b50f1dca0139b7a79fa6a258f3bbb">FLASH_Cache_Dirty</a> = 0;</div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"><a class="line" href="_flash_disk_8c.html#a0acf7a08a9d5dea843c6b55601a8cced">   38</a></span><span class="keyword">static</span> uint8_t <a class="code hl_variable" href="_flash_disk_8c.html#a0acf7a08a9d5dea843c6b55601a8cced">FLASH_Block_Cache</a>[<a class="code hl_define" href="_flash_disk_8h.html#a216f057629f42c4fa1a2d14750ac4bf0">FLASH_CACHE_SIZE</a>] __attribute__((aligned(8)));</div>
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno">   39</span> </div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno">   40</span><span class="preprocessor">#ifdef IO_SPI_ENABLE</span></div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno">   41</span><span class="preprocessor">    #include &quot;<a class="code" href="bsp__init_8h.html">bsp_init.h</a>&quot;</span></div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno">   42</span><span class="preprocessor">    #include &quot;<a class="code" href="_s_p_i___w_b25_qxx_8h.html">SPI_WB25Qxx.h</a>&quot;</span></div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno">   43</span> </div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"><a class="line" href="_flash_disk_8c.html#a6b9f438c87e2cade0b802827c695be38">   45</a></span>    <span class="keyword">static</span> <span class="keyword">volatile</span> uint8_t <a class="code hl_variable" href="_flash_disk_8c.html#a6b9f438c87e2cade0b802827c695be38">IO_SPI_Switch</a> = 0;</div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno">   46</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno">   47</span> </div>
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno"><a class="line" href="_flash_disk_8c.html#a10afa6cfd9fc23db2b431ccf9f332f30">   55</a></span><span class="keyword">static</span> __INLINE uint32_t <a class="code hl_function" href="_flash_disk_8c.html#a10afa6cfd9fc23db2b431ccf9f332f30">min</a>(uint32_t a, uint32_t b)</div>
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno">   56</span>{</div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno">   57</span>    <span class="keywordflow">return</span> (a &lt; b) ? a : b;</div>
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno">   58</span>}</div>
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno">   59</span> </div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno">   60</span><span class="comment">/*******************************************************************************************************************************************</span></div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno">   61</span><span class="comment"> * Public Function</span></div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno">   62</span><span class="comment"> *******************************************************************************************************************************************/</span></div>
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"><a class="line" href="_flash_disk_8c.html#a7655b0f2f5afc564c640878be5a50d41">   71</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="_flash_disk_8c.html#a7655b0f2f5afc564c640878be5a50d41">FlashDiskRead</a>(uint32_t addr, uint32_t size, uint8_t *buff)</div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno">   72</span>{</div>
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno">   73</span>    uint32_t block_addr_start = addr / <a class="code hl_define" href="_flash_disk_8h.html#a216f057629f42c4fa1a2d14750ac4bf0">FLASH_CACHE_SIZE</a> * <a class="code hl_define" href="_flash_disk_8h.html#a216f057629f42c4fa1a2d14750ac4bf0">FLASH_CACHE_SIZE</a>;</div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno">   74</span>    uint32_t block_addr_end = (addr + size) / <a class="code hl_define" href="_flash_disk_8h.html#a216f057629f42c4fa1a2d14750ac4bf0">FLASH_CACHE_SIZE</a> * <a class="code hl_define" href="_flash_disk_8h.html#a216f057629f42c4fa1a2d14750ac4bf0">FLASH_CACHE_SIZE</a>;</div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno">   75</span> </div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno">   76</span>    <span class="keywordflow">for</span> (uint32_t block_addr = block_addr_start; block_addr &lt;= block_addr_end; block_addr += <a class="code hl_define" href="_flash_disk_8h.html#a216f057629f42c4fa1a2d14750ac4bf0">FLASH_CACHE_SIZE</a>)</div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno">   77</span>    {</div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno">   78</span>        <span class="keywordflow">if</span> (<a class="code hl_variable" href="_flash_disk_8c.html#a3a9f0f889d7fd26864b496dd569df89a">Flash_Block_Addr</a> != block_addr)</div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno">   79</span>        {</div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno">   80</span>            <a class="code hl_function" href="_flash_disk_8c.html#a5ab90dc9341a1459125a15b506cfe35a">FlashDiskFlush</a>();</div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno">   81</span> </div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno">   82</span>            <a class="code hl_variable" href="_flash_disk_8c.html#a3a9f0f889d7fd26864b496dd569df89a">Flash_Block_Addr</a> = block_addr;</div>
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno">   83</span> </div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno">   84</span><span class="preprocessor">#ifdef IO_SPI_ENABLE</span></div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno">   85</span>            <span class="keywordflow">if</span> (<a class="code hl_variable" href="_flash_disk_8c.html#a6b9f438c87e2cade0b802827c695be38">IO_SPI_Switch</a> != 0) <span class="comment">/* IO_SPI -&gt; SFC */</span></div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno">   86</span>            {</div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno">   87</span>                <a class="code hl_function" href="dev__sfc_8c.html#aad5d116153c77313a1212733b556a578">sfc_init</a>();</div>
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno">   88</span>                <a class="code hl_variable" href="_flash_disk_8c.html#a6b9f438c87e2cade0b802827c695be38">IO_SPI_Switch</a> = 0;</div>
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno">   89</span>            }</div>
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno">   90</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno">   91</span> </div>
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno">   92</span>            SFC_Read(<a class="code hl_define" href="_flash_disk_8h.html#ac7fa8f8ed89ae3a8c6533c8d69fb31a4">DATA_FLASH_BASE</a> + <a class="code hl_variable" href="_flash_disk_8c.html#a3a9f0f889d7fd26864b496dd569df89a">Flash_Block_Addr</a>, (uint32_t *)<a class="code hl_variable" href="_flash_disk_8c.html#a0acf7a08a9d5dea843c6b55601a8cced">FLASH_Block_Cache</a>, <a class="code hl_define" href="_flash_disk_8h.html#a216f057629f42c4fa1a2d14750ac4bf0">FLASH_CACHE_SIZE</a> &gt;&gt; 2);</div>
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno">   93</span>        }</div>
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno">   94</span> </div>
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno">   95</span>        uint32_t in_block_offset = addr - <a class="code hl_variable" href="_flash_disk_8c.html#a3a9f0f889d7fd26864b496dd569df89a">Flash_Block_Addr</a>;</div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno">   96</span>        uint32_t in_block_size = <a class="code hl_function" href="_flash_disk_8c.html#a10afa6cfd9fc23db2b431ccf9f332f30">min</a>(<a class="code hl_define" href="_flash_disk_8h.html#a216f057629f42c4fa1a2d14750ac4bf0">FLASH_CACHE_SIZE</a> - in_block_offset, size);</div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno">   97</span> </div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno">   98</span>        memcpy(buff, &amp;<a class="code hl_variable" href="_flash_disk_8c.html#a0acf7a08a9d5dea843c6b55601a8cced">FLASH_Block_Cache</a>[in_block_offset], in_block_size);</div>
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno">   99</span>        buff += in_block_size;</div>
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno">  100</span>        addr += in_block_size;</div>
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno">  101</span>        size -= in_block_size;</div>
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno">  102</span> </div>
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno">  103</span>        <span class="keywordflow">if</span> (size == 0)</div>
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno">  104</span>            <span class="keywordflow">break</span>;</div>
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno">  105</span>    }</div>
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno">  106</span>}</div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno">  107</span> </div>
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno"><a class="line" href="_flash_disk_8c.html#ac9c9d4cc9fae5bccc09d1a80c7d42fc7">  116</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="_flash_disk_8c.html#ac9c9d4cc9fae5bccc09d1a80c7d42fc7">FlashDiskWrite</a>(uint32_t addr, uint32_t size, <span class="keyword">const</span> uint8_t *buff)</div>
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno">  117</span>{</div>
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno">  118</span>    uint32_t block_addr_start = addr / <a class="code hl_define" href="_flash_disk_8h.html#a216f057629f42c4fa1a2d14750ac4bf0">FLASH_CACHE_SIZE</a> * <a class="code hl_define" href="_flash_disk_8h.html#a216f057629f42c4fa1a2d14750ac4bf0">FLASH_CACHE_SIZE</a>;</div>
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno">  119</span>    uint32_t block_addr_end = (addr + size) / <a class="code hl_define" href="_flash_disk_8h.html#a216f057629f42c4fa1a2d14750ac4bf0">FLASH_CACHE_SIZE</a> * <a class="code hl_define" href="_flash_disk_8h.html#a216f057629f42c4fa1a2d14750ac4bf0">FLASH_CACHE_SIZE</a>;</div>
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno">  120</span> </div>
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno">  121</span>    <span class="keywordflow">for</span> (uint32_t block_addr = block_addr_start; block_addr &lt;= block_addr_end; block_addr += <a class="code hl_define" href="_flash_disk_8h.html#a216f057629f42c4fa1a2d14750ac4bf0">FLASH_CACHE_SIZE</a>)</div>
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno">  122</span>    {</div>
<div class="line"><a id="l00123" name="l00123"></a><span class="lineno">  123</span>        <span class="keywordflow">if</span> (<a class="code hl_variable" href="_flash_disk_8c.html#a3a9f0f889d7fd26864b496dd569df89a">Flash_Block_Addr</a> != block_addr)</div>
<div class="line"><a id="l00124" name="l00124"></a><span class="lineno">  124</span>        {</div>
<div class="line"><a id="l00125" name="l00125"></a><span class="lineno">  125</span>            <a class="code hl_function" href="_flash_disk_8c.html#a5ab90dc9341a1459125a15b506cfe35a">FlashDiskFlush</a>();</div>
<div class="line"><a id="l00126" name="l00126"></a><span class="lineno">  126</span> </div>
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno">  127</span>            <a class="code hl_variable" href="_flash_disk_8c.html#a3a9f0f889d7fd26864b496dd569df89a">Flash_Block_Addr</a> = block_addr;</div>
<div class="line"><a id="l00128" name="l00128"></a><span class="lineno">  128</span> </div>
<div class="line"><a id="l00129" name="l00129"></a><span class="lineno">  129</span><span class="preprocessor">#ifdef IO_SPI_ENABLE</span></div>
<div class="line"><a id="l00130" name="l00130"></a><span class="lineno">  130</span>            <span class="keywordflow">if</span> (<a class="code hl_variable" href="_flash_disk_8c.html#a6b9f438c87e2cade0b802827c695be38">IO_SPI_Switch</a> != 0) <span class="comment">/* IO_SPI -&gt; SFC */</span></div>
<div class="line"><a id="l00131" name="l00131"></a><span class="lineno">  131</span>            {</div>
<div class="line"><a id="l00132" name="l00132"></a><span class="lineno">  132</span>                <a class="code hl_function" href="dev__sfc_8c.html#aad5d116153c77313a1212733b556a578">sfc_init</a>();</div>
<div class="line"><a id="l00133" name="l00133"></a><span class="lineno">  133</span>                <a class="code hl_variable" href="_flash_disk_8c.html#a6b9f438c87e2cade0b802827c695be38">IO_SPI_Switch</a> = 0;</div>
<div class="line"><a id="l00134" name="l00134"></a><span class="lineno">  134</span>            }</div>
<div class="line"><a id="l00135" name="l00135"></a><span class="lineno">  135</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00136" name="l00136"></a><span class="lineno">  136</span> </div>
<div class="line"><a id="l00137" name="l00137"></a><span class="lineno">  137</span>            <span class="comment">/* 更新 Cache 块 */</span></div>
<div class="line"><a id="l00138" name="l00138"></a><span class="lineno">  138</span>            SFC_Read(<a class="code hl_define" href="_flash_disk_8h.html#ac7fa8f8ed89ae3a8c6533c8d69fb31a4">DATA_FLASH_BASE</a> + <a class="code hl_variable" href="_flash_disk_8c.html#a3a9f0f889d7fd26864b496dd569df89a">Flash_Block_Addr</a>, (uint32_t *)<a class="code hl_variable" href="_flash_disk_8c.html#a0acf7a08a9d5dea843c6b55601a8cced">FLASH_Block_Cache</a>, <a class="code hl_define" href="_flash_disk_8h.html#a216f057629f42c4fa1a2d14750ac4bf0">FLASH_CACHE_SIZE</a> &gt;&gt; 2);</div>
<div class="line"><a id="l00139" name="l00139"></a><span class="lineno">  139</span>        }</div>
<div class="line"><a id="l00140" name="l00140"></a><span class="lineno">  140</span> </div>
<div class="line"><a id="l00141" name="l00141"></a><span class="lineno">  141</span>        uint32_t in_block_offset = addr - <a class="code hl_variable" href="_flash_disk_8c.html#a3a9f0f889d7fd26864b496dd569df89a">Flash_Block_Addr</a>;</div>
<div class="line"><a id="l00142" name="l00142"></a><span class="lineno">  142</span>        uint32_t in_block_size = <a class="code hl_function" href="_flash_disk_8c.html#a10afa6cfd9fc23db2b431ccf9f332f30">min</a>(<a class="code hl_define" href="_flash_disk_8h.html#a216f057629f42c4fa1a2d14750ac4bf0">FLASH_CACHE_SIZE</a> - in_block_offset, size);</div>
<div class="line"><a id="l00143" name="l00143"></a><span class="lineno">  143</span> </div>
<div class="line"><a id="l00144" name="l00144"></a><span class="lineno">  144</span>        memcpy(&amp;<a class="code hl_variable" href="_flash_disk_8c.html#a0acf7a08a9d5dea843c6b55601a8cced">FLASH_Block_Cache</a>[in_block_offset], buff, in_block_size);</div>
<div class="line"><a id="l00145" name="l00145"></a><span class="lineno">  145</span>        buff += in_block_size;</div>
<div class="line"><a id="l00146" name="l00146"></a><span class="lineno">  146</span>        addr += in_block_size;</div>
<div class="line"><a id="l00147" name="l00147"></a><span class="lineno">  147</span>        size -= in_block_size;</div>
<div class="line"><a id="l00148" name="l00148"></a><span class="lineno">  148</span> </div>
<div class="line"><a id="l00149" name="l00149"></a><span class="lineno">  149</span>        <a class="code hl_variable" href="_flash_disk_8c.html#ac59b50f1dca0139b7a79fa6a258f3bbb">FLASH_Cache_Dirty</a> = 1;</div>
<div class="line"><a id="l00150" name="l00150"></a><span class="lineno">  150</span> </div>
<div class="line"><a id="l00151" name="l00151"></a><span class="lineno">  151</span>        <span class="keywordflow">if</span> (size == 0)</div>
<div class="line"><a id="l00152" name="l00152"></a><span class="lineno">  152</span>            <span class="keywordflow">break</span>;</div>
<div class="line"><a id="l00153" name="l00153"></a><span class="lineno">  153</span>    }</div>
<div class="line"><a id="l00154" name="l00154"></a><span class="lineno">  154</span>}</div>
<div class="line"><a id="l00155" name="l00155"></a><span class="lineno">  155</span> </div>
<div class="line"><a id="l00162" name="l00162"></a><span class="lineno"><a class="line" href="_flash_disk_8c.html#a5ab90dc9341a1459125a15b506cfe35a">  162</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="_flash_disk_8c.html#a5ab90dc9341a1459125a15b506cfe35a">FlashDiskFlush</a>(<span class="keywordtype">void</span>)</div>
<div class="line"><a id="l00163" name="l00163"></a><span class="lineno">  163</span>{</div>
<div class="line"><a id="l00164" name="l00164"></a><span class="lineno">  164</span>    <span class="comment">/* Write back the cache if it&#39;s dirty */</span></div>
<div class="line"><a id="l00165" name="l00165"></a><span class="lineno">  165</span>    <span class="keywordflow">if</span> (<a class="code hl_variable" href="_flash_disk_8c.html#ac59b50f1dca0139b7a79fa6a258f3bbb">FLASH_Cache_Dirty</a>)</div>
<div class="line"><a id="l00166" name="l00166"></a><span class="lineno">  166</span>    {</div>
<div class="line"><a id="l00167" name="l00167"></a><span class="lineno">  167</span> </div>
<div class="line"><a id="l00168" name="l00168"></a><span class="lineno">  168</span><span class="preprocessor">#ifdef IO_SPI_ENABLE</span></div>
<div class="line"><a id="l00169" name="l00169"></a><span class="lineno">  169</span>        <span class="keywordflow">if</span> (<a class="code hl_variable" href="_flash_disk_8c.html#a6b9f438c87e2cade0b802827c695be38">IO_SPI_Switch</a> == 0) <span class="comment">/* SFC -&gt; IO_SPI */</span></div>
<div class="line"><a id="l00170" name="l00170"></a><span class="lineno">  170</span>        {</div>
<div class="line"><a id="l00171" name="l00171"></a><span class="lineno">  171</span>            <a class="code hl_function" href="_s_p_i___w_b25_qxx_8c.html#a0465c5f017965876cf6ff8859eb2731f">WB25Qxx_Init</a>();</div>
<div class="line"><a id="l00172" name="l00172"></a><span class="lineno">  172</span>            <a class="code hl_variable" href="_flash_disk_8c.html#a6b9f438c87e2cade0b802827c695be38">IO_SPI_Switch</a> = 1;</div>
<div class="line"><a id="l00173" name="l00173"></a><span class="lineno">  173</span>        }</div>
<div class="line"><a id="l00174" name="l00174"></a><span class="lineno">  174</span> </div>
<div class="line"><a id="l00175" name="l00175"></a><span class="lineno">  175</span>        <a class="code hl_function" href="_s_p_i___w_b25_qxx_8c.html#a65571e7929b299af3a763c206a2c98b5">WB25Qxx_EraseSector</a>(<a class="code hl_define" href="_flash_disk_8h.html#ac7fa8f8ed89ae3a8c6533c8d69fb31a4">DATA_FLASH_BASE</a> + <a class="code hl_variable" href="_flash_disk_8c.html#a3a9f0f889d7fd26864b496dd569df89a">Flash_Block_Addr</a>);</div>
<div class="line"><a id="l00176" name="l00176"></a><span class="lineno">  176</span>        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; <a class="code hl_define" href="_flash_disk_8h.html#a216f057629f42c4fa1a2d14750ac4bf0">FLASH_CACHE_SIZE</a>; i += 256)</div>
<div class="line"><a id="l00177" name="l00177"></a><span class="lineno">  177</span>            <a class="code hl_function" href="_s_p_i___w_b25_qxx_8c.html#a6af72df055a5bc71064719f68842f515">WB25Qxx_WritePage</a>(<a class="code hl_define" href="_flash_disk_8h.html#ac7fa8f8ed89ae3a8c6533c8d69fb31a4">DATA_FLASH_BASE</a> + <a class="code hl_variable" href="_flash_disk_8c.html#a3a9f0f889d7fd26864b496dd569df89a">Flash_Block_Addr</a> + i, (uint8_t *)&amp;<a class="code hl_variable" href="_flash_disk_8c.html#a0acf7a08a9d5dea843c6b55601a8cced">FLASH_Block_Cache</a>[i], 256);</div>
<div class="line"><a id="l00178" name="l00178"></a><span class="lineno">  178</span> </div>
<div class="line"><a id="l00179" name="l00179"></a><span class="lineno">  179</span><span class="preprocessor">#else </span></div>
<div class="line"><a id="l00180" name="l00180"></a><span class="lineno">  180</span>        <span class="comment">// FLASH_CACHE_SIZE == Erase Block Size</span></div>
<div class="line"><a id="l00181" name="l00181"></a><span class="lineno">  181</span>        SFC_Erase(<a class="code hl_define" href="_flash_disk_8h.html#ac7fa8f8ed89ae3a8c6533c8d69fb31a4">DATA_FLASH_BASE</a> + <a class="code hl_variable" href="_flash_disk_8c.html#a3a9f0f889d7fd26864b496dd569df89a">Flash_Block_Addr</a>, 1);</div>
<div class="line"><a id="l00182" name="l00182"></a><span class="lineno">  182</span> </div>
<div class="line"><a id="l00183" name="l00183"></a><span class="lineno">  183</span><span class="preprocessor">        #if 1 </span><span class="comment">/* 0- 64 Word 写入      1- 4 Word 写入 </span></div>
<div class="line"><a id="l00184" name="l00184"></a><span class="lineno">  184</span><span class="comment">               * 若按 4 个字同时进行写入与显示, 仍然出现显示抖动，则改成 1 个字写入即可解决 </span></div>
<div class="line"><a id="l00185" name="l00185"></a><span class="lineno">  185</span><span class="comment">               */</span><span class="preprocessor"></span></div>
<div class="line"><a id="l00186" name="l00186"></a><span class="lineno">  186</span>        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; <a class="code hl_define" href="_flash_disk_8h.html#a216f057629f42c4fa1a2d14750ac4bf0">FLASH_CACHE_SIZE</a>; i += 16) <span class="comment">/* 4 */</span></div>
<div class="line"><a id="l00187" name="l00187"></a><span class="lineno">  187</span>            SFC_Write(<a class="code hl_define" href="_flash_disk_8h.html#ac7fa8f8ed89ae3a8c6533c8d69fb31a4">DATA_FLASH_BASE</a> + <a class="code hl_variable" href="_flash_disk_8c.html#a3a9f0f889d7fd26864b496dd569df89a">Flash_Block_Addr</a> + i, (uint32_t *)&amp;<a class="code hl_variable" href="_flash_disk_8c.html#a0acf7a08a9d5dea843c6b55601a8cced">FLASH_Block_Cache</a>[i], 4); <span class="comment">/* 1 */</span></div>
<div class="line"><a id="l00188" name="l00188"></a><span class="lineno">  188</span>        </div>
<div class="line"><a id="l00189" name="l00189"></a><span class="lineno">  189</span><span class="preprocessor">        #else</span></div>
<div class="line"><a id="l00190" name="l00190"></a><span class="lineno">  190</span>        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; <a class="code hl_define" href="_flash_disk_8h.html#a216f057629f42c4fa1a2d14750ac4bf0">FLASH_CACHE_SIZE</a>; i += <a class="code hl_define" href="_flash_disk_8h.html#abb4210984e117a7e60518a7bcf68b0af">FLASH_PAGE_WRITE_BYTES_MAX</a>)</div>
<div class="line"><a id="l00191" name="l00191"></a><span class="lineno">  191</span>            SFC_Write(<a class="code hl_define" href="_flash_disk_8h.html#ac7fa8f8ed89ae3a8c6533c8d69fb31a4">DATA_FLASH_BASE</a> + <a class="code hl_variable" href="_flash_disk_8c.html#a3a9f0f889d7fd26864b496dd569df89a">Flash_Block_Addr</a> + i, (uint32_t *)&amp;<a class="code hl_variable" href="_flash_disk_8c.html#a0acf7a08a9d5dea843c6b55601a8cced">FLASH_Block_Cache</a>[i], <a class="code hl_define" href="_flash_disk_8h.html#abb4210984e117a7e60518a7bcf68b0af">FLASH_PAGE_WRITE_BYTES_MAX</a> &gt;&gt; 2);</div>
<div class="line"><a id="l00192" name="l00192"></a><span class="lineno">  192</span>        </div>
<div class="line"><a id="l00193" name="l00193"></a><span class="lineno">  193</span><span class="preprocessor">        #endif</span></div>
<div class="line"><a id="l00194" name="l00194"></a><span class="lineno">  194</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00195" name="l00195"></a><span class="lineno">  195</span> </div>
<div class="line"><a id="l00196" name="l00196"></a><span class="lineno">  196</span>        <a class="code hl_variable" href="_flash_disk_8c.html#ac59b50f1dca0139b7a79fa6a258f3bbb">FLASH_Cache_Dirty</a> = 0;</div>
<div class="line"><a id="l00197" name="l00197"></a><span class="lineno">  197</span>    }</div>
<div class="line"><a id="l00198" name="l00198"></a><span class="lineno">  198</span>}</div>
<div class="ttc" id="a_flash_disk_8c_html_a0acf7a08a9d5dea843c6b55601a8cced"><div class="ttname"><a href="_flash_disk_8c.html#a0acf7a08a9d5dea843c6b55601a8cced">FLASH_Block_Cache</a></div><div class="ttdeci">static uint8_t FLASH_Block_Cache[FLASH_CACHE_SIZE]</div><div class="ttdoc">实际操作的 Block 区域</div><div class="ttdef"><b>Definition:</b> <a href="_flash_disk_8c_source.html#l00038">FlashDisk.c:38</a></div></div>
<div class="ttc" id="a_flash_disk_8c_html_a10afa6cfd9fc23db2b431ccf9f332f30"><div class="ttname"><a href="_flash_disk_8c.html#a10afa6cfd9fc23db2b431ccf9f332f30">min</a></div><div class="ttdeci">static __INLINE uint32_t min(uint32_t a, uint32_t b)</div><div class="ttdoc">比较两个值, 并返回较小的那个</div><div class="ttdef"><b>Definition:</b> <a href="_flash_disk_8c_source.html#l00055">FlashDisk.c:55</a></div></div>
<div class="ttc" id="a_flash_disk_8c_html_a3a9f0f889d7fd26864b496dd569df89a"><div class="ttname"><a href="_flash_disk_8c.html#a3a9f0f889d7fd26864b496dd569df89a">Flash_Block_Addr</a></div><div class="ttdeci">static volatile uint32_t Flash_Block_Addr</div><div class="ttdoc">实际操作的物理地址偏移</div><div class="ttdef"><b>Definition:</b> <a href="_flash_disk_8c_source.html#l00034">FlashDisk.c:34</a></div></div>
<div class="ttc" id="a_flash_disk_8c_html_a5ab90dc9341a1459125a15b506cfe35a"><div class="ttname"><a href="_flash_disk_8c.html#a5ab90dc9341a1459125a15b506cfe35a">FlashDiskFlush</a></div><div class="ttdeci">void FlashDiskFlush(void)</div><div class="ttdoc">刷新脏缓冲区</div><div class="ttdef"><b>Definition:</b> <a href="_flash_disk_8c_source.html#l00162">FlashDisk.c:162</a></div></div>
<div class="ttc" id="a_flash_disk_8c_html_a6b9f438c87e2cade0b802827c695be38"><div class="ttname"><a href="_flash_disk_8c.html#a6b9f438c87e2cade0b802827c695be38">IO_SPI_Switch</a></div><div class="ttdeci">static volatile uint8_t IO_SPI_Switch</div><div class="ttdoc">IO-SPI 切换标志( 1 - 使能 IO-SPI 写入; 0 - 使能 SFC 读取)</div><div class="ttdef"><b>Definition:</b> <a href="_flash_disk_8c_source.html#l00045">FlashDisk.c:45</a></div></div>
<div class="ttc" id="a_flash_disk_8c_html_a7655b0f2f5afc564c640878be5a50d41"><div class="ttname"><a href="_flash_disk_8c.html#a7655b0f2f5afc564c640878be5a50d41">FlashDiskRead</a></div><div class="ttdeci">void FlashDiskRead(uint32_t addr, uint32_t size, uint8_t *buff)</div><div class="ttdoc">读取数据</div><div class="ttdef"><b>Definition:</b> <a href="_flash_disk_8c_source.html#l00071">FlashDisk.c:71</a></div></div>
<div class="ttc" id="a_flash_disk_8c_html_ac59b50f1dca0139b7a79fa6a258f3bbb"><div class="ttname"><a href="_flash_disk_8c.html#ac59b50f1dca0139b7a79fa6a258f3bbb">FLASH_Cache_Dirty</a></div><div class="ttdeci">static volatile uint32_t FLASH_Cache_Dirty</div><div class="ttdoc">脏值标记(0 - 无须刷新 Block; 1 - 需要刷新 Block )</div><div class="ttdef"><b>Definition:</b> <a href="_flash_disk_8c_source.html#l00036">FlashDisk.c:36</a></div></div>
<div class="ttc" id="a_flash_disk_8c_html_ac9c9d4cc9fae5bccc09d1a80c7d42fc7"><div class="ttname"><a href="_flash_disk_8c.html#ac9c9d4cc9fae5bccc09d1a80c7d42fc7">FlashDiskWrite</a></div><div class="ttdeci">void FlashDiskWrite(uint32_t addr, uint32_t size, const uint8_t *buff)</div><div class="ttdoc">写入数据</div><div class="ttdef"><b>Definition:</b> <a href="_flash_disk_8c_source.html#l00116">FlashDisk.c:116</a></div></div>
<div class="ttc" id="a_flash_disk_8h_html"><div class="ttname"><a href="_flash_disk_8h.html">FlashDisk.h</a></div><div class="ttdoc">管理片外 SPI―Flash 的读写, 对接 FATFS 组件</div></div>
<div class="ttc" id="a_flash_disk_8h_html_a216f057629f42c4fa1a2d14750ac4bf0"><div class="ttname"><a href="_flash_disk_8h.html#a216f057629f42c4fa1a2d14750ac4bf0">FLASH_CACHE_SIZE</a></div><div class="ttdeci">#define FLASH_CACHE_SIZE</div><div class="ttdoc">实际读写缓存块大小 / Bytes(必须被 Erase-4096 整除)</div><div class="ttdef"><b>Definition:</b> <a href="_flash_disk_8h_source.html#l00044">FlashDisk.h:44</a></div></div>
<div class="ttc" id="a_flash_disk_8h_html_abb4210984e117a7e60518a7bcf68b0af"><div class="ttname"><a href="_flash_disk_8h.html#abb4210984e117a7e60518a7bcf68b0af">FLASH_PAGE_WRITE_BYTES_MAX</a></div><div class="ttdeci">#define FLASH_PAGE_WRITE_BYTES_MAX</div><div class="ttdoc">按页单次写入最大数据量 / Bytes (由 Flash 换页特性决定)</div><div class="ttdef"><b>Definition:</b> <a href="_flash_disk_8h_source.html#l00046">FlashDisk.h:46</a></div></div>
<div class="ttc" id="a_flash_disk_8h_html_ac7fa8f8ed89ae3a8c6533c8d69fb31a4"><div class="ttname"><a href="_flash_disk_8h.html#ac7fa8f8ed89ae3a8c6533c8d69fb31a4">DATA_FLASH_BASE</a></div><div class="ttdeci">#define DATA_FLASH_BASE</div><div class="ttdoc">管理起址&lt;如有特殊需求, 可以跳过某一段区域不托管给文件系统&gt; eg : 1、在文件系统的物理驱动层读写函数中(即 diskio.c), 将每个传参地址都同时增加一个值 X 则可以实现 0 ~ X 区域...</div><div class="ttdef"><b>Definition:</b> <a href="_flash_disk_8h_source.html#l00038">FlashDisk.h:38</a></div></div>
<div class="ttc" id="a_s_p_i___w_b25_qxx_8c_html_a0465c5f017965876cf6ff8859eb2731f"><div class="ttname"><a href="_s_p_i___w_b25_qxx_8c.html#a0465c5f017965876cf6ff8859eb2731f">WB25Qxx_Init</a></div><div class="ttdeci">void WB25Qxx_Init(void)</div><div class="ttdoc">初始化 WB25Qxx 使用的 SPI 接口, 并读取芯片 ID 等信息以判断其是否是 WB25Qxx 芯片</div><div class="ttdef"><b>Definition:</b> <a href="_s_p_i___w_b25_qxx_8c_source.html#l00154">SPI_WB25Qxx.c:154</a></div></div>
<div class="ttc" id="a_s_p_i___w_b25_qxx_8c_html_a65571e7929b299af3a763c206a2c98b5"><div class="ttname"><a href="_s_p_i___w_b25_qxx_8c.html#a65571e7929b299af3a763c206a2c98b5">WB25Qxx_EraseSector</a></div><div class="ttdeci">void WB25Qxx_EraseSector(uint32_t addr)</div><div class="ttdoc">擦除 WB25Qxx 指定扇区地址</div><div class="ttdef"><b>Definition:</b> <a href="_s_p_i___w_b25_qxx_8c_source.html#l00291">SPI_WB25Qxx.c:291</a></div></div>
<div class="ttc" id="a_s_p_i___w_b25_qxx_8c_html_a6af72df055a5bc71064719f68842f515"><div class="ttname"><a href="_s_p_i___w_b25_qxx_8c.html#a6af72df055a5bc71064719f68842f515">WB25Qxx_WritePage</a></div><div class="ttdeci">void WB25Qxx_WritePage(uint32_t addr, uint8_t *buff, uint32_t cnt)</div><div class="ttdoc">向 WB25Qxx 指定地址处写入指定个字节数据(写入前须保证待写入区域已被擦空)</div><div class="ttdef"><b>Definition:</b> <a href="_s_p_i___w_b25_qxx_8c_source.html#l00371">SPI_WB25Qxx.c:371</a></div></div>
<div class="ttc" id="a_s_p_i___w_b25_qxx_8h_html"><div class="ttname"><a href="_s_p_i___w_b25_qxx_8h.html">SPI_WB25Qxx.h</a></div><div class="ttdoc">WB25Qxx SPI Flash 驱动程序</div></div>
<div class="ttc" id="absp__init_8h_html"><div class="ttname"><a href="bsp__init_8h.html">bsp_init.h</a></div><div class="ttdoc">板级硬件外设初始化</div></div>
<div class="ttc" id="adev__sfc_8c_html_aad5d116153c77313a1212733b556a578"><div class="ttname"><a href="dev__sfc_8c.html#aad5d116153c77313a1212733b556a578">sfc_init</a></div><div class="ttdeci">void sfc_init(void)</div><div class="ttdoc">初始化 SFC 将 外挂的SPI-Flash 映射至 MCU 总线地址上</div><div class="ttdef"><b>Definition:</b> <a href="dev__sfc_8c_source.html#l00102">dev_sfc.c:102</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.5
</small></address>
</body>
</html>
